package com.example.dialog;

import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.utils.DialogUtils;
import com.example.wheelview.PicPopupWindow;
import com.orhanobut.android.dialogplussample.R;
import com.orhanobut.dialogplus.*;


/**
 *
 */
public class MainActivity1 extends AppCompatActivity {


    DialogPlus dialogPlus;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main1);

        Intent intent = new Intent(this, MainActivity.class);
        findViewById(R.id.showDialogButton).setOnClickListener(v -> showDialogPlus());
        findViewById(R.id.btn_list_dialog);
        findViewById(R.id.btn_grid_dialog);
        findViewById(R.id.btn_base_dialog).setOnClickListener(v ->{
                dialogPlus = DialogUtils.baseDialog(this,
                        "这是标题",
                        "这是信息内容",
                        intent);
                dialogPlus.show();
        });
        findViewById(R.id.btn_load_dialog).setOnClickListener(v -> loadDialog());
        Button button = findViewById(R.id.btn_date_dialog);
        button.setOnClickListener(v ->{
            dialogPlus = DialogUtils.dateDialog(this,button);
            dialogPlus.show();
        });


    }

    private void loadDialog() {
        DialogUtils.loadDialog(this);
    }

    public void showDialogPlus() {
        boolean fixedHeader = true;         // 头部固定
        boolean fixedFooter = true;         // 底部固定
        boolean isCancelable = true;        // 点击其他地方关闭
        boolean expanded = true;            // 拓展动画默认值为false，仅适用于grid和list

        // 选择位置
        int gravity_curr = Gravity.CENTER;  // 上 中 下


        // 加载布局
        boolean isGrid = false;
        int count = 5;
        Holder holder;
        Holder holder1 = new ViewHolder(R.layout.content);
        Holder holder2 = new ListHolder();
        Holder holder3 = new GridHolder(3);

        holder = holder1;
        SimpleAdapter simpleAdapter = new SimpleAdapter(this, isGrid, count);
        DialogPlusBuilder builder = DialogPlus
                .newDialog(this)
                .setContentHolder(holder)
                .setHeader(R.layout.header, fixedHeader)
                .setFooter(R.layout.footer, fixedFooter)
                .setCancelable(isCancelable)
                .setGravity(gravity_curr)
                .setAdapter(simpleAdapter)
                .setOnClickListener((dialog, view) -> {
                    if (view instanceof TextView) {
                        Toast.makeText(this, ((TextView) view).getText(), Toast.LENGTH_SHORT);

                    }
                })
                .setExpanded(expanded)
                .setOnItemClickListener((dialog, item, view, position) ->
                        Toast.makeText(this, ((TextView) view).getText(), Toast.LENGTH_SHORT))
//                .setContentHeight(500)
//                .setContentWidth(2500)
                .setOnCancelListener(dialog ->
                        Toast.makeText(this, "cancelled", Toast.LENGTH_SHORT));
//                .setContentBackgroundResource(android.R.color.transparent);


        builder.create().show();

    }






}
